# -*- coding: utf-8 -*-
# @Time    : 2022/7/16 19:16
# @Author  : catherine
# @Email   : catherine_csq@163.com
# @File    : add_customer_care_page.py
# @Software: PyCharm
from time import sleep

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from pages.base_page import BasePage

class AddCustomerCarePage(BasePage):
    '''编辑联系人界面类'''
    url='http://192.168.189.1:8081/crm/index.php?m=customer&a=caresadd'
    #定位器
    customer_name_locator = (By.ID, 'customer_name')
    selected_cname_locator = (By.XPATH, '//*[@id="datas"]/tr[1]/td[1]/input[1]')
    confirm_cname_locator = (By.XPATH, '/html/body/div[8]/div[3]/div/button[1]')
    contacts_name_locator = (By.ID, 'contacts_name')
    selected_contact_locator = (By.XPATH, '//*[@id="data2"]/tr[2]/td[1]/input')
    confirm_contact_locator = (By.XPATH, '/html/body/div[9]/div[3]/div/button[1]')
    care_theme_locator = (By.XPATH, '//*[@id="name"]')
    care_time_locator = (By.ID, 'care_time')
    care_type_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[4]/td[4]/select')
    care_content_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[5]/td[2]/textarea')
    comment_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[6]/td[2]/textarea')
    button_confirm_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')

    def input_customer_name(self):
        '''输入客户姓名'''
        self.find_element(self.customer_name_locator).click()
        sleep(0.5)
        self.find_element(self.selected_cname_locator).click()
        self.find_element(self.confirm_cname_locator).click()

    def input_contacts_name(self):
        '''输入联系人'''
        self.find_element(self.contacts_name_locator).click()
        sleep(0.5)
        self.find_element(self.selected_contact_locator).click()
        self.find_element(self.confirm_contact_locator).click()

    def input_care_theme(self,care_theme):
        '''输入关怀主题'''
        self.find_element(self.care_theme_locator).send_keys(care_theme)

    def input_care_time(self,care_time):
        '''输入关怀日期'''
        js = "document.getElementById('care_time').removeAttribute('readonly')"
        self.driver.execute_script(js)
        self.find_element(self.care_time_locator).send_keys(care_time)
        js1 = "document.getElementById('care_time').setAttribute('readonly','True')"
        self.driver.execute_script(js1)

    def input_care_type(self,care_type):
        '''输入关怀类型'''
        care_type_list = Select(self.find_element(self.care_type_locator))
        care_type_list.select_by_visible_text(care_type)

    def input_care_content(self,care_content):
        '''输入关怀内容'''
        self.find_element(self.care_content_locator).send_keys(care_content)
        return self.find_element(self.care_content_locator).text

    def input_comment(self,comment):
        '''输入备注'''
        self.find_element(self.comment_locator).send_keys(comment)

    def click_button_confirm(self):
        '''点击保存新建客户关怀'''
        self.find_element(self.button_confirm_locator).click()

